//
//  SISSAddCommentViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/18.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSAddCommentViewController.h"
#import "SISSRateBarView.h"

@interface SISSAddCommentViewController ()<SISSRateBarViewDelegate>

/// 评分Label
@property (weak, nonatomic) UILabel *scoreLabel;
/// 评分StarView
@property (weak, nonatomic) SISSRateBarView *scoreStarView;
/// 评语Label
@property (weak, nonatomic) UILabel *commentLabel;
/// 评语TextView
@property (weak, nonatomic) UITextView *commentTextView;
/// 确定按钮
@property (weak, nonatomic) UIButton *confirmButton;

/// 评分星级
@property (assign, nonatomic) NSInteger scoreStar;

@end
@interface SISSAddCommentViewController ()

@end

@implementation SISSAddCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}

#pragma mark - SISSRateBarViewDelegate
- (void)rateBarViewDidSelectedRateBarView:(SISSRateBarView *)rateBarView atIndex:(NSInteger)index {
    rateBarView.rate = index;
    self.scoreStar = index;
}

#pragma mark - 确定按钮点击事件
- (void)confirmButtonClickAction {
    
    NSLog(@" %zd \n%@",self.scoreStar,self.commentTextView.text);
}

#pragma mark - UI
- (void)setupSubviews {
    [super setupSubviews];
    
    UILabel *scoreLabel = [[UILabel alloc] init];
    scoreLabel.font = [UIFont systemFontOfSize:16];
    scoreLabel.textColor = MAIN_TEXT_COLOR;
    scoreLabel.text = @"评分：";
    [self.view addSubview:scoreLabel];
    self.scoreLabel = scoreLabel;
    
    SISSRateBarView *scoreStarView = [[SISSRateBarView alloc] init];
    scoreStarView.delegate = self;
    scoreStarView.starTintColor = [UIColor redColor];
    [self.view addSubview:scoreStarView];
    self.scoreStarView = scoreStarView;
    
    UILabel *commentLabel = [[UILabel alloc] init];
    commentLabel.font = [UIFont systemFontOfSize:16];
    commentLabel.textColor = MAIN_TEXT_COLOR;
    commentLabel.text = @"评语：";
    [self.view addSubview:commentLabel];
    self.commentLabel = commentLabel;
    
    UITextView *commentTextView = [[UITextView alloc] init];
    commentTextView.layer.borderWidth = 1;
    commentTextView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    [self.view addSubview:commentTextView];
    self.commentTextView = commentTextView;
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.view).offset(2 * margin);
        make.top.equalTo(weakSelf.view).offset(10 * margin);
    }];
    
    [self.scoreStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.scoreLabel.mas_right);
        make.centerY.equalTo(weakSelf.scoreLabel);
        make.size.mas_equalTo(CGSizeMake(200, 30));
    }];
    
    [self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.scoreLabel);
        make.top.equalTo(weakSelf.scoreLabel.mas_bottom).offset(4 * margin);
    }];
    
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.commentLabel);
        make.top.equalTo(weakSelf.commentLabel.mas_bottom);
        make.right.equalTo(weakSelf.view).offset(-2 * margin);
        make.height.mas_equalTo(10 * margin);
    }];
    
    [self.commentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.commentLabel);
        make.top.equalTo(weakSelf.commentLabel.mas_bottom);
        make.right.equalTo(weakSelf.view).offset(-2 * margin);
        make.height.mas_equalTo(10 * margin);
    }];
}

@end
